﻿// // Copyright (c) 2019 PaddlePaddle Authors. All Rights Reserved.
// //
// // Licensed under the Apache License, Version 2.0 (the "License");
// // you may not use this file except in compliance with the License.
// // You may obtain a copy of the License at
// //
// //     http://www.apache.org/licenses/LICENSE-2.0
// //
// // Unless required by applicable law or agreed to in writing, software
// // distributed under the License is distributed on an "AS IS" BASIS,
// // WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
// // See the License for the specific language governing permissions and
// // limitations under the License.

#pragma once
#include <vector>
#include <string>
#include <memory>
#include <opencv2/opencv.hpp>


namespace ai {

// class ImageBlob {
// public:
//    ImageBlob(){}
//    ImageBlob(cv::Mat* im){
//       ori_im_shape = {im->rows, im->cols};
//    }
//    ~ImageBlob(){}

//    float* im_data;
//    int data_length;

//    std::vector<int> ori_im_shape; 
//    std::vector<float>  input_shape;
//    std::vector<float> scale_factor;    // height, width

// };


// class PreProcessor {
// public:

//    // normalize and HWC_BGR -> CHW_RGB
//    static void normalize(cv::Mat& im, float* data, PDModelConfig *cfg);

//    // normalize det cla
//    static void det_normalize(cv::Mat* im, ImageBlob* data, PDModelConfig* cfg);

//    // flatten a cv::mat
//    static void flatten_mat(cv::Mat& im, float* data, PDModelConfig *cfg);

//    static void det_resize_scale(cv::Mat* im, ImageBlob* data, PDModelConfig *cfg);

//    static void det_resize(cv::Mat* im, ImageBlob* data, PDModelConfig *cfg);

//    static void cla_resize(const cv::Mat &img, cv::Mat &resize_img,
//                     int resize_short_size);

//    static void det_pad_stride(cv::Mat* im, ImageBlob* data, PDModelConfig *cfg);

//    static void det_permute(cv::Mat* im, ImageBlob* data, PDModelConfig *cfg);

//    static void cla_permute(const cv::Mat *im, float *data);

// };


class PostProcessor {
public:

   // argmax
   static void argmax(float* out, std::vector<int>& shape,
               std::vector<uchar>& mask, std::vector<uchar>& scoremap);

   template <class ForwardIterator>
   inline static size_t argmax(ForwardIterator first, ForwardIterator last) {
      return std::distance(first, std::max_element(first, last));
   }


};


// class ImagePreProcessor {
// protected:
//    ImagePreProcessor() {}
// public:
//    virtual ~ImagePreProcessor() {}

//    virtual int single_process(cv::Mat* img, 
//                               ImageBlob* data,
//                               PDModelConfig *cfg) = 0;

//    virtual int batch_process(std::vector<cv::Mat*> imgs,
//                               std::vector<ImageBlob*>& datas,
//                               PDModelConfig *cfg) = 0;
// };  // end of class ImagePreProcessor


}  // namespace paddle_infer
